<?php

namespace app\common\model\Subject;

use think\Model;
use think\Request;

class Collect extends Model
{
       //模型对应的是哪张表
       protected $name = "business_collection";

       //指定一个自动设置的时间字段
       //开启自动写入
       protected $autoWriteTimestamp = true; 

       //设置字段的名字
       protected $createTime = "createtime"; //插入的时候设置的字段名

       //禁止 写入的时间字段
       protected $updateTime = false;

       //自动过滤掉不存在的字段
       protected $field = true;

       //追加虚拟字段
       protected $append = [
        'createtime_text',
    ];

       public function getCreatetimeTextAttr($value,$data)
    {
        //获取数据
        $createtime = isset($data['createtime']) ? trim($data['createtime']) : '';

        if(empty($createtime))
        {
            return '暂无收藏时间';
        }

        return date("Y-m-d",$createtime);
    }

       //关联business表进行查询
       public function business()
       {
           return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
       }

       //关联subject表进行查询
       public function subject()
    {  
        return $this->belongsTo('app\common\model\Subject\Subject', 'collectid', 'id', [], 'LEFT')->setEagerlyType(0);
    }



      
}
